package com.epfresh.api.entity;

public class Version
{
	Version version;

	public Version getVersion() {
		return version;
	}

	public void setVersion(Version version) {
		this.version = version;
	}

	/**
	 * id : 5
	 * name : 前端文案
	 * code : allDocument
	 * version : 1
	 * remark : null
	 */

	private AllDocumentBean allDocument_version;
	/**
	 * id : 7
	 * name : 安卓供货APP版本
	 * code : androidApp_supplies
	 * version : 9
	 * remark : null
	 */

	private AndroidAppSuppliesBean androidApp_supplies;
	/**
	 * id : 2
	 * name : 地址列表
	 * code : address
	 * version : 16
	 * remark : null
	 */

	private AddressBean address;
	/**
	 * id : 6
	 * name : 安卓采购APP版本
	 * code : androidApp_purchase
	 * version : 7
	 * remark : null
	 */

	private AndroidAppPurchaseBean androidApp_purchase;
	/**
	 * id : 3
	 * name : 所有城市服务
	 * code : allcityservice
	 * version : 14
	 * remark : null
	 */

	private AllcityserviceBean allcityservice;
	/**
	 * id : 4
	 * name : 全国城市级联
	 * code : allAddress
	 * version : 1
	 * remark : null
	 */

	private AllAddressBean allAddress;
	/**
	 * id : 1
	 * name : 开通城市
	 * code : city
	 * version : 16
	 * remark : null
	 */

	private CityBean city;

	public AllDocumentBean getAllDocument() {
		return allDocument_version;
	}

	public void setAllDocument(AllDocumentBean allDocument) {
		this.allDocument_version = allDocument;
	}

	public AndroidAppSuppliesBean getAndroidApp_supplies() {
		return androidApp_supplies;
	}

	public void setAndroidApp_supplies(AndroidAppSuppliesBean androidApp_supplies) {
		this.androidApp_supplies = androidApp_supplies;
	}

	public AddressBean getAddress() {
		return address;
	}

	public void setAddress(AddressBean address) {
		this.address = address;
	}

	public AndroidAppPurchaseBean getAndroidApp_purchase() {
		return androidApp_purchase;
	}

	public void setAndroidApp_purchase(AndroidAppPurchaseBean androidApp_purchase) {
		this.androidApp_purchase = androidApp_purchase;
	}

	public AllcityserviceBean getAllcityservice() {
		return allcityservice;
	}

	public void setAllcityservice(AllcityserviceBean allcityservice) {
		this.allcityservice = allcityservice;
	}

	public AllAddressBean getAllAddress() {
		return allAddress;
	}

	public void setAllAddress(AllAddressBean allAddress) {
		this.allAddress = allAddress;
	}

	public CityBean getCity() {
		return city;
	}

	public void setCity(CityBean city) {
		this.city = city;
	}

	public static class AllDocumentBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class AndroidAppSuppliesBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class AddressBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class AndroidAppPurchaseBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class AllcityserviceBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class AllAddressBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}

	public static class CityBean {
		private int id;
		private String name;
		private String code;
		private String version;
		private Object remark;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getVersion() {
			return version;
		}

		public void setVersion(String version) {
			this.version = version;
		}

		public Object getRemark() {
			return remark;
		}

		public void setRemark(Object remark) {
			this.remark = remark;
		}
	}


	/**
	 *
	 * @param version1
	 * @param version2
	 * @return if version1 > version2, return 1, if equal, return 0, else return
	 *         -1
	 */
	public static int VersionComparison(String versionServer, String versionLocal) {
		String version1 = versionServer;
		String version2 = versionLocal;
		if (version1 == null || version1.length() == 0 || version2 == null || version2.length() == 0)
			throw new IllegalArgumentException("Invalid parameter!");

		int index1 = 0;
		int index2 = 0;
		while (index1 < version1.length() && index2 < version2.length()) {
			int[] number1 = getValue(version1, index1);
			int[] number2 = getValue(version2, index2);

			if (number1[0] < number2[0]){
				return -1;
			}
			else if (number1[0] > number2[0]){
				return 1;
			}
			else {
				index1 = number1[1] + 1;
				index2 = number2[1] + 1;
			}
		}
		if (index1 == version1.length() && index2 == version2.length())
			return 0;
		if (index1 < version1.length())
			return 1;
		else
			return -1;
	}

	public static int[] getValue(String version, int index) {
		int[] value_index = new int[2];
		StringBuilder sb = new StringBuilder();
		while (index < version.length() && version.charAt(index) != '.') {
			sb.append(version.charAt(index));
			index++;
		}
		value_index[0] = Integer.parseInt(sb.toString());
		value_index[1] = index;

		return value_index;
	}

	@Override
	public String toString() {
		return "Version{" +
				"version=" + version +
				", allDocument=" + allDocument_version +
				", androidApp_supplies=" + androidApp_supplies +
				", address=" + address +
				", androidApp_purchase=" + androidApp_purchase +
				", allcityservice=" + allcityservice +
				", allAddress=" + allAddress +
				", city=" + city +
				'}';
	}
}
